package com.myself.aop.controlleraop;

import com.myself.aop.anno.Log;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by SiFeiYang on Date 2022/4/2
 */
@Component
@Aspect
public class ControllerMethodAop {

    /**
     * 定义切点
     */
    @Pointcut(value = "@annotation(com.myself.aop.anno.Log)")
    public void aspectMethod(){
    }

    @Around(value = "aspectMethod()")
    public Object methodAround(ProceedingJoinPoint joinPoint){
        System.out.println("=====进入around=======");
        Object proceed = null;
        try {
            proceed = joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("=====aop结束====");
        return proceed;

    }
    @After("@annotation(log)")
    public void methodAfter(JoinPoint joinPoint, Log log){
        System.out.println("aop捕获到methodAfter");

    }
    @AfterReturning("@annotation(controllerLog)")
    public void methodAfterReturn(JoinPoint joinPoint,Log controllerLog){
        System.out.println("aop捕获到methodAfterReturn");
    }
    @AfterThrowing(value = "@annotation(com.myself.aop.anno.Log)",throwing = "e")
    public void methodAfterThrowing(JoinPoint joinPoint,Exception e){
        System.out.println("aop捕获到执行异常");
    }
}
